package com.wu.handler;

import com.wu.AppEngine;
import com.wu.flandre_common.entity.RpcResponse;
import com.wu.flandre_common.util.RpcRestTemp;
import lombok.extern.slf4j.Slf4j;

/**
 * EngineStateHandler <br/>
 *
 * @author 50816 <br/>
 * @date 2019/12/22 20:12 <br/>
 */
@Slf4j
public class EngineStateHandler {

    public RpcResponse<String> stop() {
        RpcResponse response = null;
        try {
            AppEngine appEngine = new AppEngine();
            appEngine.closeEngine();
            response = RpcRestTemp.success(null);
        } catch (Exception e) {
            log.error("引擎执行任务异常:" + e.getMessage());
            response = RpcRestTemp.error();
        }
        return response;
    }

    public RpcResponse<String> start() {
        RpcResponse response = null;
        try {
            AppEngine appEngine = new AppEngine();
            appEngine.bind();
            response = RpcRestTemp.success(null);
        } catch (Exception e) {
            log.error("引擎执行任务异常:" + e.getMessage());
            response = RpcRestTemp.error();
        }
        return response;
    }

    public RpcResponse<String> restart() {
        RpcResponse response = null;
        try {
            AppEngine appEngine = new AppEngine();
            appEngine.closeEngine();
            appEngine.bind();
            response = RpcRestTemp.success(null);
        } catch (Exception e) {
            log.error("引擎执行任务异常:" + e.getMessage());
            response = RpcRestTemp.error();
        }
        return response;
    }
}
